<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工单编号:" prop="order_no">
        <el-input
          v-model="orderNOO"
          placeholder="编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单状态" prop="ro_status">
        <el-select v-model="ro_status" placeholder="工单状态" clearable>
          <el-option
           v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
       <el-time-picker
    v-model="value1"
    :picker-options="{
      selectableRange: '00:00:00 - 23:59:59'
    }"
    placeholder="选择时间">
  </el-time-picker>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="myOrderList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="工单编号" width="100" align="center" prop="orderNo" />
      <el-table-column label="问题内容" align="center" prop="repairDescription" :show-overflow-tooltip="true" />
      <el-table-column label="工单发起人" width="100" align="center" prop="userName" />
      <el-table-column label="工单发起人部门" width="120" align="center" prop="deptName"/>
      <el-table-column label="工单问题类型" align="center" prop="repairTypeV1">
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="createTime" :show-overflow-tooltip="true" />
      <el-table-column label="受理时间" align="center" prop="updateTime" :show-overflow-tooltip="true" />

      <el-table-column label="状态" align="center" prop="repairStatus"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">


          <router-link :to="{path:'/dtails/'+orderone}">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['monitor:job:edit']"
          > 查看</el-button>

          </router-link>


          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['monitor:job:edit']"
          >链接</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['monitor:job:remove']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
// import { listJob, getJob, delJob, addJob, updateJob, runJob, changeJobStatus } from "@/api/monitor/job";
// import Crontab from '@/components/Crontab'
import {selectAcceptOrder}from "@/api/work/accept"
import Log from "@/views/monitor/job/log";
export default {
  // components: { Crontab },
  name: "Accept",
  components: {},

  data() {
    return {
      //时间选择器
      value1: new Date(2022, 3, 9, 13, 40),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 定时任务表格数据
      myOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示详细弹出层
      openView: false,
      orderone: '',
      orderNOO : '',
      ro_status : '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: '',
        ro_status: this.value,
        create_time: undefined,
      },
      //工单状态
       options: [{
          value: '1',
          label: '工单已分配'
        }, {
          value: '2',
          label: '工单未分配'
        }, {
          value: '3',
          label: '工单'
        }, {
          value: '4',
          label: '龙须面'
        }, {
          value: '5',
          label: '北京烤鸭'
        }],
        value: ''
      ,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        order_no: [
          { required: true, message: "工单编号不能为空", trigger: "blur" }
        ],
        ro_status: [
          { required: true, message: "工单状态不能为空", trigger: "blur" }
        ],
        create_time: [
          { required: true, message: "提交时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询我的工单列表 */
    getList() {
     this.queryParams.orderNo = this.orderNOO
      this.queryParams.ro_status = this.ro_status
      this.loading = true;
      selectAcceptOrder(this.queryParams).then(response => {
        // this.orderNo=this.orderNOO
        this.myOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 表单重置
    reset() {
      this.form = {
        order_no: undefined,
        ro_description : undefined,
        ro_status: undefined,
        create_time: undefined,
        ro_type: undefined,


      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.order_no);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.orderone = row.orderNo
      this.$cache.session.set('key', this.orderone)
      const jobId = row.order_no || this.ids;
      getJob(jobId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改任务";

      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const order_noIds = row.order_no || this.ids;
      this.$modal.confirm('是否确认删除定时任务编号为"' + order_noIds + '"的数据项？').then(function() {
        return delOrder(order_noIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },

  }
};
</script>
